import { ref } from "vue"
import { PAGE, PAGE_SIZE } from "@/constant"
export function useTable(tabelRef){
    // 组件
    const _ref = tabelRef
    // 页码
    const usePage = ref(PAGE)
    const useSize = ref(PAGE_SIZE)
    /**
     * 重置页码
     */
    const useSearch = () => {
        usePage.value = PAGE
        _ref.value?.setCurrentPage(PAGE)
    }
    const useReset = () => {
        usePage.value = PAGE
        useSize.value = PAGE_SIZE
        _ref.value?.setCurrentPage(PAGE)
        _ref.value?.setCurrentPageSize(PAGE_SIZE)
    }
    /**
     * 设置总数
     * @param { Number } val 
     */
    const uesSetTotal = (val) => {
        _ref.value?.setTotal(val*1)
    }

    return {
        uesSetTotal,
        usePage,
        useSize,
        useSearch,
        useReset
    }
}